Viewing the table data:

1. Display all the rows and columns
ex: select * from <tableName>;
select * from emp;

2. Selected rows and all the columns?
ex: Select * from <tableName> where <condition>;
select * from emp where job='SALESMAN';

3. All the rows and selected columns?
ex: Select <col1>, <col2>,... from <tableName>;
select EMPNO, ENAME, JOB, SAL from emp;


4. Selected rows and selected columns?
ex: Select <col1>, <col2>,... from <tableName> where <condition>;
select EMPNO, ENAME, JOB, SAL from emp where deptno = 30;


5. Display only unique records (without duplicate)?
Ans: Use DISTINCT keyword
Ex: 
select distinct (<col1>) from <tableName>;
Ex: select distinct(id) from sample;
select distinct <col1>, <col2>,.. from <tableName>;
Ex: select DISTINCT id, name, city, age from sample;


6. Sort the table records?
Ans: Use ORDER BY keyword
ex: 
(i) select <col1>,<col2> from <tableName> ORDER BY <col1>,<col2> asc;

(ii) select <col1>,<col2> from <tableName> ORDER BY <col1> desc;

(iii) select <col1>,<col2> from <tableName> where <condition>
ORDER BY <col1> asc/desc;

select * from sample order by id asc;
select * from sample order by id,name desc;
select * from sample where age=21 order by id desc;



